cc.Class({
    extends: cc.Component,

    properties: {

    },

    onLoad() {
        this.node.on('click', this.onToggleOn, this);
        this.node.on('click_cancel', this.onToggleOff, this);
        this.icon = this.node.find('img_bet_icon');
        this.count = this.node.find('txt_count', cc.Label);
    },

    onToggleOn() {
        this.icon.y = 26;
        this.icon.opacity = 255;
        this.icon.runAction(cc.scaleTo(0.3, 1.2).easing(cc.easeBackOut()));
        this.count.node.color = cc.hexToColor('#ffb922');
    },

    onToggleOff() {
        this.icon.y = 16;
        this.icon.stopAllActions();
        this.icon.setScale(0.9);
        this.icon.opacity = 155;
        this.count.node.color = cc.hexToColor('#ffffff');
    },

    getCount() {
        return parseInt(this.count.string);
    },

    flyOil(node) {
        var icon = cc.instantiate(this.icon);
        icon.parent = this.node;
        var pos1 = node.parent.convertToWorldSpaceAR(node.position);
        var pos2 = icon.parent.convertToNodeSpaceAR(pos1);
        icon.runAction(cc.sequence(
            cc.jumpTo(0.5, pos2.x, pos2.y, (pos2.y - icon.y), 1).easing(cc.easeQuadraticActionInOut()),
            cc.scaleTo(0.2, 0).easing(cc.easeSineIn()),
            cc.callFunc(() => icon.parent = null, this)
        ));
    }

});
